package dm.bsi;

import java.lang.reflect.Field;

import dm.service.DpServiceManager;
import dm.service.Manager;
import dm.service.MysqlManager;
import dm.service.RedisSentinelManager;
import indi.zjh.dp.db.Session;
import indi.zjh.dp.orm.Relation;

public class MSDeployment extends Deployment {
	protected int expectedMasterCount = 0;
	protected int expectedSlaveCount = 0;	
	
	public void processContainer(Session session) throws Exception
	{
		// 获取关联的Service
		Service service = this.getService(session);
		
		Manager manager = null;
		if(service.getCatalog() == Service.CATALOG_REDIS_SENTINEL)
		{
			manager = new RedisSentinelManager();
		}
		else if(service.getCatalog() == Service.CATELOG_MYSQL)
		{
			manager = new MysqlManager();
		}
		
		manager.process(session, this, service);
	}
	
	public static String toDictString(Field f)
	{
		if(f.getName().equals("expectedMasterCount"))
		{
			return "期待的主节点个数";
		}
		else if(f.getName().equals("expectedSlaveCount"))
		{
			return "期待的从节点个数";
		}
		return Deployment.toDictString(f);
	}

	public int getExpectedMasterCount() {
		return expectedMasterCount;
	}

	public void setExpectedMasterCount(int expectedMasterCount) {
		this.expectedMasterCount = expectedMasterCount;
	}

	public int getExpectedSlaveCount() {
		return expectedSlaveCount;
	}

	public void setExpectedSlaveCount(int expectedSlaveCount) {
		this.expectedSlaveCount = expectedSlaveCount;
	}

	

	@Override
	public String toString() {
		return "MSDeployment [expectedMasterCount=" + expectedMasterCount + ", expectedSlaveCount=" + expectedSlaveCount
				+ ", name=" + name + ", description=" + description + ", hostPort=" + hostPort + ", secondHostPort="
				+ secondHostPort + ", containerPort=" + containerPort + ", curContainerPort=" + curContainerPort
				+ ", curId=" + curId + ", mode=" + mode + ", tryCount=" + tryCount + ", service=" + service + ", image="
				+ image + ", _id=" + _id + ", _v=" + _v + "]";
	}
	
	
}
